import requests


class IHRMLoginApi:

    # 封装登录接口
    @classmethod
    def ihrm_login_api(cls, login_body):
        login_url = "http://ihrm2-test.itheima.net/api/sys/login"
        login_header = {"Content-Type": "application/json"}
        login_resp = requests.post(url=login_url, headers=login_header, json=login_body)
        return login_resp

    # 封装添加接口
    @classmethod
    def ihrm_add_api(cls, token, add_emp_body):
        add_emp_url = 'http://ihrm2-test.itheima.net/api/sys/user'
        add_emp_header = {"Content-Type": "application/json", "Authorization": token}
        add_emp_resp = requests.post(url=add_emp_url, headers=add_emp_header, json=add_emp_body)
        return add_emp_resp

    # 封装查询接口
    @classmethod
    def ihrm_query_emp_api(cls, token, emp_id):
        search_emp_url = 'http://ihrm2-test.itheima.net/api/sys/user/' + emp_id
        search_emp_header = {"Authorization": token}
        search_emp_resp = requests.get(url=search_emp_url, headers=search_emp_header)
        return search_emp_resp

    # 封装修改接口
    @classmethod
    def update_emp_api(cls, token, emp_id, update_emp_body):
        update_emp_url = 'http://ihrm2-test.itheima.net/api/sys/user/' + emp_id
        update_emp_header = {"Content-Type": "application/json", "Authorization": token}
        update_emp_resp = requests.put(url=update_emp_url, headers=update_emp_header, json=update_emp_body)
        return update_emp_resp

    # 封装删除接口
    @classmethod
    def delete_emp_api(cls, emp_id, token):
        delete_emp_url = ' http://ihrm2-test.itheima.net/api/sys/user/' + emp_id
        delete_emp_header = {"Authorization": token}
        del_resp = requests.delete(url=delete_emp_url)
        return del_resp

